package com.mimiwang.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mimiwang.article.dao.ArticlePhotoDao;
import com.mimiwang.article.entity.ArticlePhotoEntity;
import com.mimiwang.article.service.ArticlePhotoService;
import com.mimiwang.common.utils.PageUtils;
import com.mimiwang.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("articlePhotoService")
public class ArticlePhotoServiceImpl extends ServiceImpl<ArticlePhotoDao, ArticlePhotoEntity> implements ArticlePhotoService {

    @Autowired
    private ArticlePhotoDao articlePhotoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ArticlePhotoEntity> page = this.page(
                new Query<ArticlePhotoEntity>().getPage(params),
                new QueryWrapper<ArticlePhotoEntity>()
        );

        return new PageUtils(page);
    }

    /*根据文章id将图片路径存入到数据库里面*/
    @Override
    public boolean savePhoto(Long articleId, String s) {
        ArticlePhotoEntity entity = new ArticlePhotoEntity();
        entity.setArticleId(articleId);
        entity.setPhotoUrl(s);
        int insert = articlePhotoDao.insert(entity);
        System.out.println("insert:"+insert);
        if (insert>0){
            return true;
        }else {
            return false;
        }
    }

}